package leetcode_1000;

import java.util.Stack;

/**
 *@author 周杨
 *ValidateStackSequences_946 给定两个int数组 判断pop数组能否通过push数组 栈操作完成
 *describe:用栈 AC
 *2018年11月25日 下午6:20:58
 */
public class ValidateStackSequences_946 {
	public boolean validateStackSequences(int[] pushed, int[] popped) {
	       Stack<Integer> stack=new Stack<Integer>();
	       int index=0;//指向pop
	       for(int i:pushed) {
	    	   stack.add(i);
	    	   while(!stack.isEmpty()&&stack.peek()==popped[index]) {
	    		   stack.pop();
	    		   ++index;
	    	   }
	       }
	       return stack.isEmpty();
	}
}
